Enable configuration of the JSON-RPC error object to be returned.
#18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Background
This PR is a proposal.
Currently, the
modelcontextprotocol/ruby-sdkdelegates the handling ofJSON-RPCerror objects to thejson-rpc-handler, which prevents flexible configuration of error objects returned by the SDK.For example, The logging utility should return the
JSON-RPCerror object-32602,Invalid params, when the log level is invalid.https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#error-handling
Currently, however, the
modelcontextprotocol/ruby-sdkside cannot freely configure theInvalid paramserror object. Therefore, we implemented a solution in which you can return the intendedJSON-RPCerror object by including code in the error class and raising it.The
modelcontextprotocol/ruby-sdkcould define and returnJSON-RPCerror objects directly. However, I believe that delegating this responsibility to thejson-rpc-handlerkeeps things simpler.For this use case, setting
ErrorCode::InvalidParamsflexibly would have been sufficient.However, I implemented it this way because I thought that allowing the flexible invocation of other error classes would make it more universally reusable.